

# 有降级反爬 爬取失败
#
import re, json, execjs, httpx

url = 'https://www.zongheng.com/rank?nav=one-day-update&rankType=10'
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36'}
html = httpx.Client(http2=True, follow_redirects=True).get(url, headers=headers, timeout=10).text

m = re.search(r'window\.-_NUxT--=\((function.*?\)\);)', html, re.S)
if not m:
    raise RuntimeError('正则没匹配到 JS 块')
js_block = m.group(1)

# 在 JS 引擎里跑一遍，拿到原始对象
js = f'const res = {js_block}; JSON.stringify(res)'
data = json.loads(execjs.eval(js))

print(data['state']['rank']['popularityRank']['newOrderRankList'][:3])   # 榜单前 3 本